// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import '@/styles/index.scss'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import {
  isLogin
} from '@/api/index'
import VueCookies from 'vue-cookies'
Vue.use(VueCookies)
Vue.use(ElementUI)
Vue.use(ElementUI)
Vue.config.productionTip = false

// 全局守卫
router.beforeEach((to, from, next) => {
  isLogin().then(res => {
    console.log(res)
    if (res.success) {
      next()
    } else {
      if (to.path === '/login') {
        next()
      } else {
        next({
          'path': '/login'
        })
      }
    }
  })
})
// 全局混入
Vue.mixin({
  data () {
    return {
      page: 1,
      pageSize: 10
    }
  },
  methods: {
    resetForm (formName) {
      this.$refs[formName].resetFields()
    }
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: {
    App
  },
  template: '<App/>'

})
